#ifndef wikiproclib_h
#define wikiproclib_h

#ifndef PROCS
#define PROCS 4
#endif

#ifndef REPULSION_POWER
#define REPULSION_POWER			0.1
#endif

#ifndef REPULSION_DISTANCE
#define REPULSION_DISTANCE		10
#endif

#ifndef OPTIMAL_DISTANCE
#define OPTIMAL_DISTANCE		0.5
#endif

#ifndef TOLERANCE
#define TOLERANCE		0.1
#endif



typedef struct {
	float x;
	float y;
	float z;
} loc;

typedef struct {
	char * title;
	int namespace;
	int id;
	int len;
	int nroflinks;
	int alloclinks;
	int* links;
	loc loc;
} wikipage;

#define sqr(i)	i * i

wikipage* load_pages(const char* filename, int* index, int* nr_pages);

typedef struct {
	int max;
	int* ids;
} id_idx;

id_idx create_id_index(wikipage* pages, int nr_page);

void load_categories(wikipage* pages, const int nr_page, const char* filename);

void load_links(wikipage* pages, const int nr_page, int* index, id_idx* idindex, const char* filename);

float distance(loc loc1, loc loc2);

/**
 * Repulsion between two disconnected nodes.
 */
loc repulsion(loc sun, loc planet);

/**
 * Attraction between two connected nodes.
 */
loc attraction(loc sun, loc planet);

loc vector(loc from, loc to);

loc add(loc first, loc second);

loc sub(loc first, loc second);

float length(loc l);

#endif
